﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace RTUParameterConfig.Class
{
    public class MessageInfo
    {
        [DllImport("user32.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", EntryPoint = "SendMessage")]
        public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);

        public static void SendMessage(string strFormName, int msg, int type, int index)
        {
            //通过窗口名获取句柄
            IntPtr hwnd = FindWindow(null, strFormName);
            if (hwnd != IntPtr.Zero)
            {
                //向窗口发送消息
                SendMessage(hwnd, msg, type, index);
            }
        }
    }
}
